/**
 * @Desc:
 * @User: zouqihui
 * @Date: 2022/12/8 15:27
 */
package models

import (
	"fmt"
	"github.com/beego/beego/v2/server/web"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var GormDB *gorm.DB

func init() {

	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn, err := web.AppConfig.String("defaultdb")
	if err != nil {
		return
	}
	//dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
	GormDB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("gorm 数据库连接失", err)
	}
}
